package com.ruoyi.web.schedule.task;



import com.ruoyi.web.config.JobTaskConfig;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

@Slf4j
public class CheckProgrammeTaskHandle {

    private static Logger logger = LoggerFactory.getLogger(CheckProgrammeTaskHandle.class);

    private static CheckProgrammeTaskHandle instance = new CheckProgrammeTaskHandle();

    public static CheckProgrammeTaskHandle getInstance() {
        return instance;
    }

    private volatile boolean programmeThreadToStop = false;


    public static final long PRE_READ_MS = 5000;    // pre read

    private Thread programmeThread = new Thread(new Runnable() {


        @Override
        public void run() {

            try {
                // 1分钟
                TimeUnit.DAYS.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            while (!programmeThreadToStop) {
                try {
                    // 下次执行时间小于当前时间 状态为启动 执行模式为定时 执行状态不等于开始执行
                    JobTaskConfig.getAdminConfig().getOrgDetailYearService().saveYearData();

                } catch (Exception e) {
                    e.printStackTrace();
                }
                finally {
                    try {
                        TimeUnit.DAYS.sleep(30);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }
    });


    public void start() {

        programmeThread.setDaemon(true);
        programmeThread.setName("发现任务线程");
        programmeThread.start();

    }

}
